package com.hyperchain.service.Impl;

import cn.hutool.json.JSONObject;
import com.hyperchain.entity.MongoStudent;
import com.hyperchain.service.MongoService;
import org.bson.Document;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.management.Query;
import java.util.ArrayList;
import java.util.List;

@Service
public class MongoServiceImpl implements MongoService {

    @Resource
    private MongoTemplate oneMongoTemplate;

    @Override
    public int insertStudent(MongoStudent student) {
        JSONObject object1 = new JSONObject();
        object1.put("name", "一灰灰blog");
        object1.put("desc", "欢迎关注一灰灰Blog");
        object1.put("age", 28);

        JSONObject object2 = new JSONObject();
        object2.put("name", "一灰灰blog1");
        object2.put("desc", "欢迎关注一灰灰Blog1");


        // 插入一条document
        oneMongoTemplate.insert(object1, "mongo_test");
        oneMongoTemplate.insert(object2, "mongo_test");

        return 1;
    }
}
